<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="../common/css/insert.css">
<style type="text/css">
	td,th,tr {
		border:solid #428bca; 
		border-width:0px 1px 1px 0px;
		text-align:center;
		line-height:30px;
		overflow:hidden;
	}
	
	table {
		border:solid #428bca; 
		border-width:1px 0px 0px 1px;
		width:90%;
	}
	
	button {
    font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
    background-color: #d9534f;
    border-color: #d43f3a; 
    color: #fff;
    display: inline-block;
    font-weight: 400;
    text-align: center;
    cursor: pointer;
    border: 1px solid transparent;
    font-size: 14px;
    line-height: 1.4285;
    border-radius: 4px;
}
	
</style>

<title>UncheckedCommentSearch</title>
</head>
<body onload="toSearch()">
	<div>
		<label>结果显示：</label>
	</div>
	<div>
	<table id="searchResults"></table>
		
	</div>
	
	<script src="../js/jquery-1.9.1.min.js"></script>  
	<script src="../js/jquery.form.js"></script> 
	<script>
	function toSearch(){
		$(document).ready(function() {
			$.ajax({
				type : "post",
				url : "../getUncheckedComments.action",
				dataType : "json",
				success : function(comments) {
					
					var table = document.getElementById('searchResults');

					//循环行
					for(var i=0;i<=comments.length;i++)
			        {
						 var tr = document.createElement('tr');
				         
						if(i==0){
				            
							 var thCommentId = document.createElement('th');
					         var thUserId = document.createElement('th');
					         var thBookId = document.createElement('th');
					         var thTime = document.createElement('th');
					         var thState = document.createElement('th');
					         var thContent = document.createElement('th');
					         var thStar = document.createElement('th');
					         var thCheckButton = document.createElement('th');
				            
				       		thCommentId.innerHTML="评论ID";
				            thUserId.innerHTML="用户ID";
				            thBookId.innerHTML="书籍ID";
				            thTime.innerHTML="评论时间";
				            thState.innerHTML="评论状态";
				            thContent.innerHTML="评论内容";
				            thStar.innerHTML="评星";
				            thCheckButton.innerHTML="审核按钮";
				            
				            
				             tr.appendChild(thCommentId);
					         tr.appendChild(thUserId);
					         tr.appendChild(thBookId);
					         tr.appendChild(thTime);
					         tr.appendChild(thState);
					         tr.appendChild(thContent);
					         tr.appendChild(thStar);
					         tr.appendChild(thCheckButton);
						}else{
			            	
			            	var tdCommentId = document.createElement('td');
				         	var tdUserId = document.createElement('td');
				         	var tdBookId = document.createElement('td');
				         	var tdTime = document.createElement('td');
				         	var tdState = document.createElement('td');
				         	var tdContent = document.createElement('td');
				         	var tdStar = document.createElement('td');
				         	var checkButton = document.createElement('button');
			            	
			            	tdCommentId.innerHTML=comments[i-1].commentid;
				            tdUserId.innerHTML=comments[i-1].userid;
				            tdBookId.innerHTML=comments[i-1].bookid;
				            tdTime.innerHTML=comments[i-1].time;
				            tdState.innerHTML=comments[i-1].state;
				            tdContent.innerHTML=comments[i-1].content;
				            tdStar.innerHTML=comments[i-1].star;
				            checkButton.innerHTML="审核";
				            
 
				             tr.appendChild(tdCommentId);
					         tr.appendChild(tdUserId);
					         tr.appendChild(tdBookId);
					         tr.appendChild(tdTime);
					         tr.appendChild(tdState);
					         tr.appendChild(tdContent);
					         tr.appendChild(tdStar);
					         tr.appendChild(checkButton);
					         
					         $(checkButton).click(function(){
					        	 //var commentid=tdCommentId.innerHTML;
					        	 var row = $(this).parent()[0].rowIndex;
					        	 var commentid=table.rows[row].cells[0].innerHTML;
					        	 //alert(commentid);
					        	 
					        	 var jo={
					        		"commentid":commentid
					        	 };
					        	 
					        	 
					        	 $.ajax({
					     			type : "post",
					     			url : "../checkComment.action",
					     			dataType : "json",
					     			data : jo,
					     			success : function(data) {
					     				if(data.status=="succeed"){
					     					alert("审核成功");
					     					location.reload();
					     					
					     					
					     				}else if(data.status=="failed"){
					     					alert("审核失败");
					     				}
					     				
					     			}
					        	 });
					         });
						}
						
						table.appendChild(tr);
			        }
				}
			});
		});
	}

	</script>
	
</body>
</html>